package com.jiajia.study.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: RabbitConfigTtlQueue
 * @Author zjj
 * @Package com.jiajia.study.config
 * @Date 2024/3/9 15:29
 * @description:
 */

@Component
public class RabbitConfigTtlQueue {

    @Bean
    public DirectExchange directExchangeB(){
        return ExchangeBuilder.directExchange("ttl.exchange.b").build();
    }

    @Bean
    public Queue queueB(){
        Map<String,Object> arguments = new HashMap<>();
        // 100 秒消息就过期
        arguments.put("x-message-ttl",100 * 1000);
        return QueueBuilder.durable("ttl.queue_queue.b").withArguments(arguments).build();
    }

    @Bean
    public Binding bindingB(DirectExchange directExchangeB, Queue queueB){
        return BindingBuilder.bind(queueB).to(directExchangeB).with("ttl.queue");
    }
}
